package cn.lsq.org.controller;

import cn.lsq.basic.utils.AjaxResult;
import cn.lsq.basic.utils.PageList;
import cn.lsq.org.domain.Logininfo;
import cn.lsq.org.query.LogininfoQuery;
import cn.lsq.org.service.LogininfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/logininfo")
public class LogininfoController {
    @Autowired
    private LogininfoService logininfoService;
    @GetMapping("/{id}")
    public Logininfo getOne(@PathVariable("id")Long id){
        return logininfoService.loadById(id);
    }

    @GetMapping
    public List<Logininfo> getAll(){
        return logininfoService.loadAll();
    }

    @PostMapping
    public PageList<Logininfo> getPage(@RequestBody LogininfoQuery logininfoQuery){
        return logininfoService.queryPage(logininfoQuery);
    }

    @PutMapping
    public AjaxResult saveAndUpdate(@RequestBody Logininfo logininfo){
        try {
            if (logininfo.getId()==null){
                logininfoService.save(logininfo);
            }else {
                logininfoService.update(logininfo);
            }
            return new AjaxResult();
        } catch (Exception e){
            e.printStackTrace();
            return new AjaxResult(false,"fuck");
        }


    }

    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id")Long id){
        try {
            logininfoService.remove(id);
            return new AjaxResult();
        } catch (Exception e){
            e.printStackTrace();
            return new AjaxResult(false,"fuck");
        }
    }
    @PatchMapping
    public AjaxResult patchDelete(@RequestBody Long[] ids){
        try {
            logininfoService.patchDelete(ids);
            return new AjaxResult();
        } catch (Exception e){
            e.printStackTrace();
            return new AjaxResult(false,"fuck");
        }
    }
}
